
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package projetluc;

import java.text.DateFormat;
import java.text.ParseException;

/**
 *
 * @author patricksamson236
 */
public class DateUtils {

    /*public static boolean isValidDateStr(String date) {
        try {
            DateFormat df =
                    DateFormat.getDateInstance(DateFormat.SHORT); // YYYY-MM-DD
            df.setLenient(false);   // this is important!
            df.parse(date);
        } catch (ParseException e) {
            return false;
        } catch (IllegalArgumentException e) {
            return false;
        }
        return true;
    }*/

    public static boolean isValidDateInt(int year, int month, int day) {
        boolean valide = true;

        //conditions de base base base...
        if (year < 1900 || month < 1 || month > 12 || day < 1 || day > 31) {
            valide = false;
        }

        //mois 30 ou 31...
        switch (month) {
            case 2:
                if (year % 4 == 0) {
                    if (year % 100 == 0) {
                        if (year % 400 == 0) {
                            if (day > 29) {
                                // %4, %400 bisextile
                                valide = false;
                            }
                        } else {
                            if (day > 28) {
                                // %100 -> PAS bisextile
                                valide = false;
                            }
                        }
                    } else {
                        if (day > 29) {
                            // %4 mais pas %100 --> bisextile
                            valide = false;
                        }
                    }
                } else {
                    if (day > 28) {
                        // pas %4 --> annee normale
                        valide = false;
                    }
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                if (day > 30) {
                    valide = false;
                }
                break;
        }
        
        return valide;
    }
}
